package net.tree;



public class demo {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8,9,10,11};
        int key =10;
        int result=search(arr,key);

   if (result==-1){
            System.out.println("找不到");
        }else {
            System.out.println("找到了：");

        }

    }

    private static int search(int[] arr, int key) {

        int left=0;
        int right=arr.length-1;
        int mid;
        while (left<=right){
            mid=(left+right)/2;

            if (key<arr[mid]){
                right=mid-1;
            }else if (key>arr[mid]){
                left=mid+1;
            }else {
                return arr[mid];
            }

        }
        return -1;
    }

}
